home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / comm / tcp / rxsocket.lha / reserv.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1998-04-04  |  1.4 KB  |  81 lines

  1. /*
  2.     Il server accetta  una stringa fino a 256 caratteri sulla porta 4000
  3.     e al rinvia in ordine inverso.
  4.  
  5. */
  6.  
  7. if ~show("L","rexxsupport.library") then do
  8.     if ~addlib("rexxsupport.library",0,-30) then do
  9.         say "no rexxsupport.library"
  10.         exit
  11.     end
  12. end
  13.  
  14. if ~show("L","rxsocket.library") then do
  15.     if ~addlib("rxsocket.library",0,-30) then do
  16.         say "no rxsocket.library"
  17.         exit
  18.     end
  19. end
  20.  
  21. if ~Open("STDERR","*","W") | ~OpenPort("REVSERVPORT") then exit
  22.  
  23. sock=socket("INET","STREAM","IP")
  24. if sock<0 then do
  25.     say "Non posso aprire il socket:" Errno()
  26.     exit
  27. end
  28.  
  29. local.ADDRFAMILY = "INET"
  30. local.ADDRADDR    = 0
  31. local.ADDRPORT   = 4000
  32. if bind(sock,"LOCAL")<0 then do
  33.     say "Non posso allocare la porta:" Errno()
  34.     exit
  35. end
  36.  
  37. sig = 2**PortSignal("REVSERVPORT")
  38. SEL.READ.0=sock
  39. open = 1
  40. do while open
  41.  
  42.     if Listen(sock,5)<0 then do
  43.         say "Errore Listen():" Errno()
  44.         exit
  45.     end
  46.  
  47.     res = WaitSelect("SEL",,,sig)
  48.  
  49.     pkt = GetPkt("REVSERVPORT")
  50.     if pkt ~= Null() then do
  51.         comm= GetArg(pkt)
  52.         call Reply(pkt)
  53.         if UPPER(comm) == "QUIT" then open = 0
  54.     end
  55.  
  56.     if SEL.0.READ then do
  57.  
  58.         lsock = Accept(sock,"REMOTE")
  59.         if lsock<0 then do
  60.             say "Errore Accept():" Errno()
  61.             exit
  62.         end
  63.  
  64.         len = recv(lsock,"BUF",256)
  65.         if ( len > 0 ) then do
  66.             BUF=Reverse(BUF)
  67.             if send(lsock,BUF) ~= length(BUF) then do
  68.                 say "send: error" Errno())
  69.             end
  70.         end
  71.         if ( len < 0 ) & ( errno() ~= 35 )
  72.             then call say "recv: error" Errno()
  73.  
  74.         call CloseSocket(lsock)
  75.  
  76.     end
  77.  
  78. end
  79.  
  80. exit
  81.